//
//  TMMindTableView.m
//  TMFishTravel
//
//  Created by Playboy on 2017/11/28.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "TMMindTableView.h"
#import "PBMyDeputeCell.h"
#import "PBMyOrderCell.h"
#import "PBComfimHomeController.h"
#import "PBHomeDetailController.h"

static NSString * const kPBMyDeputeCell = @"PBMyDeputeCell";
static NSString * const kPBMyOrderCell  = @"PBMyOrderCell";

@interface TMMindTableView ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation TMMindTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.estimatedRowHeight = 0;
        self.estimatedSectionHeaderHeight = 0;
        self.estimatedSectionFooterHeight = 0;
        self.dataSource = self;
        self.delegate = self;
        [self registerNib:[UINib nibWithNibName:kPBMyDeputeCell bundle:nil] forCellReuseIdentifier:kPBMyDeputeCell];
        [self registerNib:[UINib nibWithNibName:kPBMyOrderCell bundle:nil] forCellReuseIdentifier:kPBMyOrderCell];
    }
    return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.type isEqualToString:@"待付款"] || [self.type isEqualToString:@"已完成"]) {
        PBMyOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:kPBMyOrderCell forIndexPath:indexPath];
        cell.jumpVC = self.jumpVC;
        [cell refreshWithModel:self.dataArray[indexPath.section]];
        return cell;
    }
    PBMyDeputeCell *cell = [tableView dequeueReusableCellWithIdentifier:kPBMyDeputeCell forIndexPath:indexPath];
    [cell refreshWithModel:self.dataArray[indexPath.section]];
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 180;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.type isEqualToString:@"待付款"] || [self.type isEqualToString:@"已完成"]) {
        PBMyOrderModel *model = self.dataArray[indexPath.section];
        PBHomeDetailModel *homeModel = [[PBHomeDetailModel alloc] init];
        homeModel.cover = model.content[@"cover"];
        homeModel.name = model.content[@"name"];
        homeModel.rent = model.content[@"price"];
        homeModel.area = @"85";
        PBPayTypeModel *payModel = [[PBPayTypeModel alloc] init];
        payModel.name = model.remark;
        payModel.price = model.amount;
        
        PBComfimHomeController *vc = [[PBComfimHomeController alloc] init];
        vc.model = homeModel;
        vc.payModel = payModel;
        vc.isOrder = YES;
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }else if ([self.type isEqualToString:@"未完成的"] || [self.type isEqualToString:@"已完成的"]) {
        PBMyOrderModel *model = self.dataArray[indexPath.section];
        PBHomeDetailController *vc = [[PBHomeDetailController alloc] init];
        vc.houseId = [NSString stringWithFormat:@"%zd",model.houseId];
        [self.jumpVC.navigationController pushViewController:vc animated:YES];
    }
}

@end
